package project.cti.excel.main;

import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import project.cti.excel.util.ExcelUtil;
import file.FileUtil;
import file.ReadFileUtil;

/**
 * <BR>
 *
 *
 * VERSION        NAME        DATE        REASON
 * ----------------------------------------------------------------------------
 * 1.00           Brian       Feb 12, 2012  Create
 * @author brian
 * @version 1.00
 */
public class App {

    private static final String FILE_NAME_FILE = "/home/brian/workspace/saber-project-util-tools/src/main/java/project/cti/excel/conf/file-name";
    private static final String RES_DIR = "/home/brian/temp/copy";
    private static final String RES_SHEET_NAME = "软件开发日语实务教程";
    private static final int RES_ROW_NUM = 0;
    private static final String RES_CELL_NAME = "日本語単語,中国語";
    private static final String PARTITION = ",";
    private static final String FILE_TYPE = ".xls";

    /**
     * 
     * @param args
     * @throws UnsupportedEncodingException 
     * @throws FileNotFoundException 
     */
    public static void main(String[] args) throws Exception {

        String[] cellNames = RES_CELL_NAME.split(PARTITION);
        List<String> searchFiles = ReadFileUtil.getFileAllRow(FILE_NAME_FILE);
        List<String> files = FileUtil.getFilesByDir(RES_DIR);
        int count = 0;
        for (String file : files) {
            for (String searchFile : searchFiles) {
                Pattern pattern = Pattern.compile(".*" + searchFile + ".*\\" + FILE_TYPE);
                Matcher matcher = pattern.matcher(file);
                if (matcher.matches()) {
                    System.out.println(file);
                    ExcelUtil.readExcel(file, RES_SHEET_NAME, RES_ROW_NUM, cellNames);
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}
